package middleware

import (
	"github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
	"time"
)

/**
 * @Description 跨域配置
 * @Date 2023/5/16 周二 9:32
 * @Author Tang-J-L <vx：17685112557>
 */

func Cors() gin.HandlerFunc {
	config := cors.Config{
		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTION"},
		AllowHeaders:     []string{"Origin", "Content-Type", "Authorization", "Accept", "token"},
		ExposeHeaders:    []string{"Content-Length"},
		AllowCredentials: true,
		AllowOriginFunc: func(origin string) bool {
			return true // 允许任何站点访问
		},
		MaxAge: 12 * time.Hour,
	}
	return cors.New(config)
}
